﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;

namespace UnitTestProject.Util_Web
{
    [TestClass]
    public class TestMyTcpClient
    {
        [TestInitialize]
        public void init()
        { 
        
        }

        [TestMethod]
        public void TestClient()
        {
            var client = new Util.Web.MyTcpClient(true);
            // client.Start("192.168.1.215", "48001");
            client.Start("192.168.1.251", "48001");

            client.ReceiveText += (o, a) =>
            {
                string msg = $"Msg:\n{a.Msg}\nHex:\n{a.Hex}";
                Console.WriteLine(msg);
            };

            client.StatusChange += (o, a) =>
            {
                Console.WriteLine(a.ConsoleMsg);
            };

            while (true)
            {
                // client.Send("client send 123 一二三");
                client.StandardSend("client send 123 一二三");
                System.Threading.Thread.Sleep(5000);
            }
        }


        [TestMethod]
        public void TestServer()
        {
            var server = new Util.Web.MyTcpServer();
            server.StartServer("0.0.0.0", "48001");

            server.ReceiveText += (o, a) =>
            {
                string msg = $"Msg:\n{a.Msg}\nHex:\n{a.Hex}";
                Console.WriteLine(msg);
            };

            server.StatusChange += (o, a) =>
            {
                Console.WriteLine(a.ConsoleMsg);
            };

            while (true)
            {
                // client.Send("client send 123 一二三");
                server.StandardSend("client send 123 一二三");
                System.Threading.Thread.Sleep(5000);
            }
        }
    }
}
